package org.zjvis.datascience.common.formula;

/**
 * @description TODO
 * @date 2022/1/24
 */
public class FormulaUtil {

    /**
     * trim formula result by specific precision num
     * @param result
     * @param precisionNum
     * @return
     */
    public static String resultTrim(String result, Integer precisionNum) {
        if (result.split("\\.").length == 1) {
            result += ".";
        }
        //填充0 的 最长长度是10
        result = String.format("%-" + (result.length() + 10) + "s", result).replace(" ", "0");
        if (precisionNum.equals(0)) {
            result = result.split("\\.")[0];
        } else {
            result = result.substring(0, result.indexOf('.') + precisionNum + 1);
        }
        return result;
    }
}
